<template>
	<view class="items">
		<view class="item" v-for="(item,index) in list" :key="index" @click="toDetail(item)">
			<view class="top">
				<u-avatar :src="item.userInfo.avatar"></u-avatar>
				<view class="" style="flex: 1;margin-left: 20rpx;">
					<view class="">
						{{item.userInfo.username || '--'}}
					</view>
					<view class="" style="color: #7B7878;font-size: 24rpx;">
						{{formatTimestamp(item.createtime)}}
					</view>
				</view>
				<u-icon name="trash-fill" color="#14C906" size="23"></u-icon>
			</view>
			<view class="" style="margin: 10rpx 0;">
				{{item.title}}
			</view>
			<view class="imgs">
				<image :src="img" mode="" v-for="(img,ind) in item.images" :key="ind"></image>
			</view>
			<view class=""
				style="display: flex;align-items: center;justify-content: space-between;margin-top: 20rpx;display: none;">
				<view class="">
					总共7天
				</view>
				<view class="">
					倒计时 <text style="margin-left: 10rpx;color: #14C906;">05:24:23</text>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		infoList,
		userMoneyLog,
		myViewInfo
	} from "@/request/api/tiezi.js"
	export default {
		data() {
			return {
				uInfo: {},
				list: []
			}
		},
		onShow() {
			this.uInfo = uni.getStorageSync("userInfo");
			infoList({
				user_id: this.uInfo.id,
				pageSize: 100
			}).then(res => {
				this.list = res.data.data.map(item => {
					item.images = item.images.split(',');
					return item
				})
			})
		},
		methods: {
			toDetail(item) {
				uni.navigateTo({
					url: "/pages/detail/detail1?id=" + item.id
				})
			},
			formatTimestamp(timestamp) {
				// 创建 Date 对象
				const date = new Date(timestamp * 1000); // 将时间戳转换为毫秒

				// 获取年份、月份、日期、小时、分钟、秒
				const year = date.getFullYear();
				const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始，需要加1
				const day = String(date.getDate()).padStart(2, '0');
				const hour = String(date.getHours()).padStart(2, '0');
				const minute = String(date.getMinutes()).padStart(2, '0');
				const second = String(date.getSeconds()).padStart(2, '0');

				// 返回格式化的日期时间字符串
				return `${year}-${month}-${day}`;
			},
		}
	}
</script>

<style scoped lang="scss">
	.items {
		border-radius: 20rpx;
		padding: 30rpx;

		.item {
			border-radius: 20rpx;
			background-color: white;
			padding: 30rpx;
			margin-bottom: 20rpx;

			.top {
				display: flex;
				align-items: center;

				image {
					width: 80rpx;
					height: 80rpx;
					border-radius: 100px;
					margin-right: 20rpx;
				}

				.more {
					width: 40rpx;
					height: 10rpx;
					margin-right: 0;
				}
			}

			.imgs {
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;

				image {
					width: 190rpx;
					height: 190rpx;
					border-radius: 30rpx;
					margin-bottom: 10rpx;
				}
			}
		}
	}
</style>